package com.example.sneakerappforme1105.dao;

import androidx.room.Dao;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;

import com.example.sneakerappforme1105.bean.OrderItem;

import java.util.List;

@Dao
public interface OrderItemDao {
    // 订单项随着订单删除
    // 查询某个订单的所有商品
    @Query("SELECT * FROM tb_orderItem WHERE orderId = :orderId")
    List<OrderItem> getOrderItemsByOrderId(long orderId);   // 用到这个

    // 查询某个商品的所有订单
    @Query("SELECT * FROM tb_orderItem WHERE goodsId = :goodsId")
    List<OrderItem> getOrdersItemByGoodsId(long goodsId);




    @Insert(onConflict = OnConflictStrategy.REPLACE)
    long insertOrderItem(OrderItem orderItem);  // 创建订单的时候需要插入，用到

    @Query("DELETE FROM tb_orderItem WHERE orderId =:orderId") // 设置删除语句
    void deleteOrderItemsByOrderId(long orderId); // 删除和orderId关联的所有 orderId
}
